package com.ziyan.utils;

import com.ziyan.error.ErrorCode;
import com.ziyan.error.UCException;
import org.junit.After;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Value;

/**
 * Created by ZMy on 2017/5/24.
 */
//@Configuration
public class URLUtil {

    /**
     * 根据long生成url
     *
     * @return
     */
    public static final String genUrl(Long id) {
        if (id == null) {
            throw new UCException(ErrorCode.system_error);
        }
        long n = id.longValue();
        StringBuilder sb = new StringBuilder();
        while (n > 0) {
            long t = n % 62L;
            n /= 62L;
            if (t < 26) {
                sb.append((char) (t + 'a'));
            } else if (t < 52) {
                t -= 26;
                sb.append((char) (t + 'A'));
            } else {
                sb.append(t - 52);
            }
        }
        return sb.toString();
    }

    public static boolean isUrl(String url) {
        return url.startsWith("http://") || url.startsWith("https://");
    }

//    @Test
//    public void test() {
//        for (long i = 1L; i < 999999L; i++) {
//            System.out.println(genUrl(i));
//        }
//    }
}
